/*
vim: syntax=groovy
-*- mode: groovy;-*-
 * -------------------------------------------------
 *  NGI-ChIPseq Nextflow config file
 * -------------------------------------------------
 * Default config options for all environments.
 * Cluster-specific config options should be saved
 * in the conf folder and imported under a profile
 * name here.
 */

// Global default params, used in configs
params {
  outdir = "/bulk_chipseq"
  genomesbase = "/bulk_chipseq/ref_genome"
  samtools {
    memory = 2000000000
  }
  macsconfig = "/tables/configfile_bulk_chipseq.txt"
  genomes {
    'hg38' {
       bowtie_name = "Homo_sapiens.GRCh38"
       size = 3049315783
    }
  }
}

// Set params profile
singularity.autoMounts = true
singularity.enabled = true
singularity.cacheDir ='/hpcapps/opt/'

profiles {	
  standard {
     process{
	container = '/hpcapps/opt/core/pipelines/chip_seq.0.1.5.simg'
	executor = 'sge'
	penv = 'make'
	queue = 'batch.q'
	}
    }
}

def timestamp() {
    def now = new Date()
    now.format("yyyyMMdd_HHmm", TimeZone.getTimeZone('UTC'))
}

timeline {
  enabled = true
  file = "chipseq_timeline_${timestamp()}.html"
}

trace {
  enabled = true
  file = "chipseq_trace_${timestamp()}.txt"
}

report {
  enabled = true
  file = "chipseq_report_${timestamp()}.html"
  }

// Capture exit codes from upstream processes when piping
process.shell = ['/bin/bash', '-euo', 'pipefail']

// Function to ensure that resource requirements don't go beyond
// a maximum limit
def check_max(obj, type) {
  if(type == 'memory'){
    if(obj.compareTo(params.max_memory) == 1)
      return params.max_memory
    else
      return obj
  } else if(type == 'time'){
    if(obj.compareTo(params.max_time) == 1)
      return params.max_time
    else
      return obj
  } else if(type == 'cpus'){
    return Math.min( obj, params.max_cpus )
  }
}
